﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LumenWorks.Framework.IO.Csv;
using System.IO;

namespace SmartText.Converter
{
    class CSVToList
    {
        public static List<Dictionary<string, string>> Load(string fileName, Encoding encoding)
        {
            using (var reader = new CsvReader(new StreamReader(fileName, encoding), true))
            {
                var headers = reader.GetFieldHeaders();
                return reader.Select(
                            line => line.ToDictionary(
                                key => headers[Array.IndexOf(line, key)],
                                value => value
                                )
                    ).ToList();
            }
        }
    }
}
